package com.studio701.carguard.controller;


import com.studio701.carguard.pojo.RespBean;
import com.studio701.carguard.pojo.UserEquipment;
import com.studio701.carguard.service.IUserEquipmentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xjc
 * @since 2022-04-11
 */
@RestController
@RequestMapping("/user-equipment")
public class UserEquipmentController {
    @Autowired
    IUserEquipmentService iUserEquipmentService;

    @ApiOperation("添加设备")
    @PostMapping("/")
    public boolean insertEquipment(@RequestBody UserEquipment userContact){
        return iUserEquipmentService.save(userContact);
    }

    @ApiOperation("删除设备")
    @DeleteMapping("/")
    RespBean deleteEquipment(Integer id){
        if (iUserEquipmentService.removeById(id)){
            return RespBean.success("删除成功");
        }else {
            return RespBean.error("删除失败");
        }
    }

    @ApiOperation("获取设备")
    @GetMapping("/")
    List<UserEquipment> getEquipmentByUserId(Integer id){
        return iUserEquipmentService.getEquipmentByUserId(id);
    }




}
